//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System;
using System.Web.UI.WebControls;

using CommunityServer.Blogs.Components;
using CommunityServer.Components;
using CommunityServer.Controls;

namespace CommunityServer.Blogs.Controls
{
    /// <summary>
    /// Summary description for CategoryDisplay.
    /// </summary>
    public class CategoryDisplay : WeblogThemedControl
    {
        public CategoryDisplay()
        {
		
        }

        /// <summary>
        /// Attaches controls need to display category data
        /// </summary>
        protected override void AttachChildControls()
        {
            IText title = FindText( "Title" );
            IText body = FindText( "body" );
            HyperLink rss = FindControl( "rss" ) as HyperLink;

            int CategoryID = 0;
            if(Context.Request.QueryString["CategoryID"] != null)
            {
                double cid = 0;
                if(Double.TryParse( Context.Request.QueryString["CategoryID"], System.Globalization.NumberStyles.Integer, null, out cid ))
                    CategoryID = (int)cid;
            }

            if(CategoryID >=0)
            {
                PostCategory pc = PostCategories.GetCategory(CategoryID,this.CurrentWeblog.SectionID,false);
                if(pc != null)
                {
                    if(title != null)
                        title.Text = pc.Name;
                    
                    if(body != null)
                        body.Text = pc.Description;

                    if(rss != null)
                    {
                        rss.Visible = true; //ct == CategoryType.BlogPost;
                        if(rss.Visible)
                            rss.NavigateUrl = BlogUrls.Instance().Rss(this.CurrentWeblog.ApplicationKey,CategoryID);
                    }

                    this.SetPageTitle(pc.Name);
                }

            }
        }

    }
}
